<%@page import="com.sun.java.swing.plaf.windows.resources.windows"%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="images/backgrounds/MBC.jpg">
<head>
  <style type="text/css">
  body{ margin:0;padding:0}
    a {text-decoration: none}
    .main{ margin-left:auto; margin-right:auto;height:50px; width:100%; background-color:rgb(0, 128, 255);margin-bottom:10px; position: fixed;overflow:hidden; z-index:10;
    	box-shadow:1px 1px 2px rgb(0, 0, 0); -webkit-box-shadow: 1px 1px 1px rgb(0, 0, 0);
     }
    .main img{ width:50px; height:50px;}
    #printbox{ background-color:#989898; padding-top:60px;overflow: visible;z-index:1;}
    #printicon{ width:1024px; margin-left:auto; margin-right:auto; padding-top: 10px; }
    /*.btn{ border: none; color: red; cursor: pointer; font-weight: bold; height: 30px;-moz-border-radius:2px;}*/
    
    .btn_excel{ 
    
   /*  background:red url('../images/Excel.gif') no-repeat top left; */
    width:80px;
    height:35px;
    border: none;
    cursor: pointer;
    -moz-border-radius:2px;
    }
    
    .btn_pdf{ 
    
    /* background:red url('../images/pdf.gif') no-repeat top left; */
    width:80px;
    height:35px;
    border: none;
    cursor: pointer;
    -moz-border-radius:2px;
    }
    
    .btn_printing{ 
    
   /*  background:red url('../images/printing.gif') no-repeat top left; */
    width:80px;
    height:35px;
    border: none;
    cursor: pointer;
    -moz-border-radius:2px;
    }
    
    .btnbeauty {
    	border:1px solid rgb(48, 121, 237);
    	text-shadow:0pt 1px rgba(0, 0, 0, 0.1);
    	-webkit-text-shadow:0pt 1px rgba(0, 0, 0, 0.1);
    	background-image:-moz-linear-gradient(center top , rgb(77, 144, 254), rgb(71, 135, 237));
    }
    


  </style>
  <link rel="stylesheet" href="plugings/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="plugings/font-awesome-4.0.3/css/font-awesome.min.css" />
<link rel="stylesheet" href="plugings/perfect_scroll/perfect-scrollbar.min.css" />
  
  <script type="text/javascript" language="javascript">
  window.onbeforeunload = function (event) {
	  	$.ajax({
	  		url: "rAttribute.jsp?title=" + getParameterByName("title") + "&id=" + getParameterByName("id"),
	  		context: document.body,
	  		error: function(jqXHR, exception) {
	  			
	  		}, success: function() {
	  			
	  		}
	  	});
  };

  function setTitle() {
		document.getElementsByTagName("title")[0].innerHTML = getParameterByName("title");
		/* title[0].innerHTML = '<%= session.getAttribute("reporttitle")%>'; */
		
		var reportbody = document.getElementById("printbox");
		reportbody.setAttribute("style", "background:none repeat scroll 0% 0% rgb(51, 68, 84);");
		
		var marqueetitle = document.getElementById("marqueetitle");
		marqueetitle.innerHTML += "TDW SUPPLIER - " + getParameterByName("title");
	}
	
	function getParameterByName(name) {
	    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
	        results = regex.exec(location.search);
	    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
	}
	
	function which(name) {
		if(name == "pdf")
			window.location = 'pdfprint.jsp?title=' + getParameterByName('title') + '&id=' + getParameterByName('id');
		else if(name == "excel")
			window.location = 'excelprint.jsp?title=' + getParameterByName('title') + '&id=' + getParameterByName('id');
		else if(name == "print")
			window.location = 'Printing.jsp?title=' + getParameterByName('title') + '&id=' + getParameterByName('id');
		else if(name == "home")
			window.location = 'reportviewer.jsp?title=' + getParameterByName('title') + '&id=' + getParameterByName('id');
	}
  </script>
</head>
<body onload="setTitle();">
<div class="main">
	<div style="margin-left:20px;margin-top:5px">
		<button type="button" class="btnbeauty btn btn-warning" style="height:40px; width:100px;" onClick="JavaScript:which('pdf')" alt="PDF Print">
		<span class="glyphicon glyphicon-file"></span>
		PDF
		</button>
		<button type="button" class="btnbeauty btn btn-success" style="height:40px; width:100px" onClick="JavaScript:which('excel')">
		<span class="glyphicon glyphicon-floppy-open"></span>
		Excel
		</button>
		<button type="button" class="btnbeauty btn btn-danger" style="height:40px; width:100px" onClick="JavaScript:which('print')">
		<span class="glyphicon glyphicon-print"></span>
		Print
		</button>
		<button type="button" class="btnbeauty btn btn-info" style="height:40px; width:100px" onClick="JavaScript:which('home')">
		<span class="glyphicon glyphicon-home"></span>
		Home
		</button>
	</div> 
	<div style="margin-top:-30px;float: right">
		<marquee style="width:800px;color:yellow;text-shadow:2pt 2px rgba(0, 0, 0, 0.1);" scrollamount="5" id="marqueetitle"></marquee>
	</div>
</div>
<div id="printbox">
		<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
		<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporter"%>
		<%@page import="java.io.File"%>
		<%@page import="java.util.List"%>
		<%@page import="java.io.*"%>
		<%@page import="net.sf.jasperreports.engine.JasperExportManager"%>
		<%@page import="java.io.OutputStream"%>
		<%@page import="net.sf.jasperreports.engine.export.JRPdfExporterParameter"%>
		<%@page import="net.sf.jasperreports.engine.JRExporterParameter"%>
		<%@page import="net.sf.jasperreports.engine.export.JRPdfExporter"%>
		<%@page import="net.sf.jasperreports.engine.JasperPrint"%>
		<%@page import="net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter"%>
		<%@page import="net.sf.jasperreports.engine.export.JRXlsExporterParameter"%>
		<%@page import="net.sf.jasperreports.engine.export.HtmlExporter"%>
		<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporterParameter"%>
		<%@page import="net.sf.jasperreports.engine.*"%>
		<%@page import="net.sf.jasperreports.engine.export.*"%>
		<%@page import="net.sf.jasperreports.engine.design.*" %>
		<%@page import="net.sf.jasperreports.j2ee.servlets.*" %>
		
	
		
		<%
		
			int pageIndex = 0;
			int lastPageIndex = 0;
			StringBuffer sbuffer = new StringBuffer();
		try{
				if(request.getParameter("title") != null) {
					if(request.getSession().getAttribute(request.getParameter("title") + request.getParameter("id")) == null)
						request.getSession().setAttribute(request.getParameter("title") + request.getParameter("id"), (JasperPrint)request.getSession().getAttribute("report_data"));
				}
				request.getSession().removeAttribute("report_data");
				JasperPrint jasperPrint = (JasperPrint)request.getSession().getAttribute(request.getParameter("title") + request.getParameter("id"));
					
				JasperPrintManager.printReport(jasperPrint, true);
				
				HtmlExporter exporter = new HtmlExporter();

				session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
				
				exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
				exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
				exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image=");		
				exporter.exportReport();
				
				
		}catch (Exception e) {
	           System.out.print("Exceptiion" + e);
	      }			
	%>
	</div>
	</body>
	</html>